package com.csd.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.csd.activity.PaymentActivity;
import com.csd.activity.R;
import com.csd.bean.Peccancy;

public class PeccancyAdapter extends BaseAdapter {

	List<Peccancy> list;
	Context context;
	
	public PeccancyAdapter(List<Peccancy> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub]
		View view = null;
		ViewHolder holder;
		 if(convertView == null){
			 view = LayoutInflater.from(context).inflate(R.layout.peccancy_item, null);
			 holder = new ViewHolder();
			 TextView tv_time = (TextView) view.findViewById(R.id.peccany_time);
			 TextView tv_id = (TextView) view.findViewById(R.id.peccancy_id);
			 TextView tv_carbrand  = (TextView) view.findViewById(R.id.peccancy_carbrand);
			 TextView tv_plate = (TextView) view.findViewById(R.id.peccancy_plate);
			 TextView tv_address = (TextView) view.findViewById(R.id.peccancy_addrees);
			 TextView tv_action = (TextView) view.findViewById(R.id.peccancy_action);
			 TextView tv_fee = (TextView) view.findViewById(R.id.peccancy_fee);
			 TextView tv_state = (TextView) view.findViewById(R.id.peccancy_state);
			 TextView tv_order = (TextView) view.findViewById(R.id.peccancy_order);
			 Button bt_pay = (Button) view.findViewById(R.id.bt_pay);
			 holder.tv_time = tv_time;
			 holder.tv_id = tv_id;
			 holder.tv_carbrand = tv_carbrand;
			 holder.tv_plate = tv_plate;
			 holder.tv_address = tv_address;
			 holder.tv_action = tv_action;
			 holder.tv_fee = tv_fee;
			 holder.tv_state = tv_state;
			 holder.tv_order = tv_order;
			 holder.bt_pay = bt_pay;
			 view.setTag(holder);
		 }else{
			 view = convertView;
			 holder = (ViewHolder) view.getTag();
		 }
		 Peccancy peccancy = list.get(position);
		holder.tv_time.setText(peccancy.getTime());
		holder.tv_id.setText(peccancy.getId());
		holder.tv_carbrand.setText(peccancy.getCar().getCarBrand());
		holder.tv_plate.setText(peccancy.getCar().getPlate());
		holder.tv_address.setText(peccancy.getAddress());
		holder.tv_action.setText(peccancy.getAction());
		holder.tv_fee.setText("￥"+peccancy.getFee());
		holder.tv_state.setText(peccancy.getState());
		holder.tv_order.setText(peccancy.getOrder().getOrderId());
		holder.bt_pay.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(context, PaymentActivity.class);
				context.startActivity(intent);
			}
		});
		return view;
	}

	private class ViewHolder{
		private TextView tv_time,tv_id,tv_carbrand,tv_plate,tv_address,tv_action,tv_fee,tv_state,tv_order;
		private Button bt_pay;
	}
}
